<template>
    <div class="box">
        <div class="login">
            <div class="content">
                <div class="up">
                    <img class="loginimg" src="../../assets/logo00.png" alt="">
                    <h4>营销语料标注工具</h4>
                </div>
                <div class="data">
                    <div class="count">账户登录</div>
                    <!-- 输入框 -->
                    <div class="login_form">
                        <input type="text" class="qxs-ic_user" placeholder="账户" v-model="userId">
                        <input type="text" class="qxs-ic_password" placeholder="密码" v-model="password">
                        <el-button class="login_btn" @click.native="submit" type="primary" :loading="isBtnLoading">登录
                        </el-button>
                    </div>
                </div>
            </div>
        </div>
    </div>

</template>

<script>
    import axios from "axios"
    import { Login } from "../../api/http.js"
    export default {
        name: 'Login',
        data() {
            return {
                userId: "",
                password: "",
                isBtnLoading: false,
            }
        },
        mountd() {
        },
        methods: {
            //登录
            async submit() {
                //弹框信息
                if (!this.userId) {
                    this.$message.error('请输入账户');
                    return;
                }
                if (!this.password) {
                    this.$message.error('请输入密码');
                    return;
                }

                axios.post('/api/login', { userId: this.userId, password: this.password }).then(res => {
                    console.log(res.data)
                    if (res.data.code === 0) {
                        if (res.data.data.role == '1') {
                            // alert("成功")

                            localStorage.setItem("userinfo", JSON.stringify(res.data));

                            this.$router.push("/page")
                        } else {
                            
                            localStorage.setItem("userinfo", JSON.stringify(res.data));

                            this.$router.push("/finish")
                        }
                    } else {
                        alert("有误")
                        this.$router.push("/login")
                    }
                }).catch(err => {
                    console.log(err);
                })



            }
        },
    }
</script>
<style scoped>
    .box {
        width: 1920px;
        height: 1360px;
    }

    .login {
        width: 100%;
        height: 100%;
        background: #eee
    }

    .content {
        width: 368px;
        height: 600px;
        margin: 73px auto;
    }

    .up {
        width: 368px;
        height: 165px;
        background: rgba(35, 115, 214, 1);
    }

    .login-img {
        width: 368px;
    }

    h4 {
        width: 368px;
        height: 48px;
        line-height: 48px;
        text-align: center;
        color: white;
        background: rgba(35, 115, 214, 1);
    }

    .data {
        width: 368px;
        height: 338px;
    }

    .count {
        width: 120px;
        height: 34px;
        line-height: 34px;
        text-align: center;
        border-bottom: 3px solid rgba(35, 115, 214, 1);
        margin: 20px auto;
        color: rgba(35, 115, 214, 1);
    }

    .qxs-ic_user,
    .qxs-ic_password {
        width: 368px;
        height: 40px;
        border: none;
        padding-left: 20px;
        box-sizing: border-box;
    }

    .qxs-ic_password {
        margin-top: 24px;
    }

    .advice {
        width: 96px;
        height: 22px;
    }

    .auto {
        margin: 24px 248px 24px 0px;
    }

    .login_btn {
        width: 368px;
        height: 40px;
        margin: 30px 0px;
        background: rgba(35, 115, 214, 1);
    }
</style>